/*
 * To change this template, choose Tools | Templates
 * and open the template in the editor.
 */
package com.prabhu.cmdwindow.ui;

/**
 *  Display Class is used to display strings with design like a report.
 *
 *  you may run the example by using java -cp PropertiesFramework.jar test.PropsTestCmd
 *
 * @author Pinky
 */
public abstract class Display
{

    char lHeaderStartChar = '+';
    char lHeaderMidChar = '-';
    char lHeaderEndChar = '+';
    char lLineStartChar = '|';
    char lLineEndChar = '|';
    int lScreenLength;
    int lRightPad;

    /**
     * Creating Display Object by Specifying the Screen Size and Padding
     * @param pScreenLength Length of the screen to be print
     * @param pRightPad Padding size on right side
     */
    protected Display( int pScreenLength, int pRightPad )
    {
        lScreenLength = pScreenLength;
        lRightPad = pRightPad;
    }

    /**
     * Creating Display Object by Specifying with default Screen size and padding
     */
    protected Display()
    {
        lScreenLength = 78;
        lRightPad = 5;
    }

    /**
     * Print empty second column
     * @return The printed String.
     */
    protected String printColumn2()
    {
        return printColumn2( "", "" );
    }

    /**
     * Print empty first column
     * @return The printed String.
     */
    protected String printColumn1()
    {
        return printColumn1( "", "" );
    }

    /**
     * Print empty single column
     * @return The printed String.
     */
    protected String printColumn()
    {
        return printColumn( "", "" );
    }

    /**
     * Print text as single column at center
     * @param PrintText Text to be printed
     * @return The printed String
     */
    protected String printColumn( String PrintText )
    {
        int length = PrintText.length();
        int lScrLength = (lScreenLength - 2 - length) / 2;
        int y = (lScreenLength - 2 - length) % 2;
        String lStringToPrint = "" + lLineStartChar;
        for ( int i = 0; i < (lScrLength + y); i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }
        lStringToPrint = lStringToPrint + PrintText;
        for ( int i = 0; i < lScrLength; i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }
        lStringToPrint = lStringToPrint + lLineEndChar;
        System.out.println( lStringToPrint );
        return lStringToPrint;
    }

    /**
     * Print text as single column at right aligned
     * @param PrintText Text to be printed
     * @return The printed String
     */
    protected String print( String PrintText )
    {
        int length = PrintText.length();
        int lScrLength = (lScreenLength - 2 - length);
        int y = (lScreenLength - 2 - length) % 2;
        String lStringToPrint = "" + lLineStartChar;
        lStringToPrint = lStringToPrint + PrintText;
        
        for ( int i = 0; i < lScrLength; i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }
        lStringToPrint = lStringToPrint + lLineEndChar;
        System.out.println( lStringToPrint );
        return lStringToPrint;
    }

    /**
     * Print the text on either first or second column
     * @param columnNo  even - prints on first column
     *                  odd -  prints on second column
     * @param PrintText1 Key text
     * @param PrintText2 value text
     * @return The printed String
     */
    protected String printColumn( int columnNo, String PrintText1,
                                  String PrintText2 )
    {
        if ( (columnNo % 2) == 0 )
        {
            return printColumn1( PrintText1, PrintText2 );
        }
        else
        {
            return printColumn2( PrintText1, PrintText2 );
        }
    }

    /**
     * Print the text on either first column
     * @param PrintText1 Key text
     * @param PrintText2 value text
     * @return The printed String
     */
    protected String printColumn1( String PrintText1, String PrintText2 )
    {
        int lScrLength = ((lScreenLength / 2)) / 2;
        String lStringToPrint = "" + lLineStartChar;
        for ( int i = 1; i < lRightPad; i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }
        lStringToPrint = lStringToPrint + PrintText1;
        for ( int i = lStringToPrint.length(); i < lScrLength; i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }
        if ( PrintText1.length() + PrintText2.length() == 0 )
        {
            lStringToPrint = lStringToPrint + "  ";
        }
        else
        {
            lStringToPrint = lStringToPrint + ": ";
        }
        lStringToPrint = lStringToPrint + PrintText2;
        lScrLength = lScrLength + lScrLength;
        for ( int i = lStringToPrint.length(); i < lScrLength; i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }

        System.out.print( lStringToPrint );
        return lStringToPrint;
    }

    /**
     * Print the text on either second column
     * @param PrintText1 Key text
     * @param PrintText2 value text
     * @return The printed String
     */
    protected String printColumn2( String PrintText1, String PrintText2 )
    {
        int lScrLength = ((lScreenLength / 2)) / 2;
        String lStringToPrint = "";
        for ( int i = 1; i < lRightPad; i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }
        lStringToPrint = lStringToPrint + PrintText1;
        for ( int i = lStringToPrint.length(); i < lScrLength; i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }
        if ( PrintText1.length() + PrintText2.length() == 0 )
        {
            lStringToPrint = lStringToPrint + "  ";
        }
        else
        {
            lStringToPrint = lStringToPrint + ": ";
        }
        lStringToPrint = lStringToPrint + PrintText2;
        lScrLength = lScrLength + lScrLength;
        for ( int i = lStringToPrint.length(); i <= lScrLength; i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }
        lStringToPrint = lStringToPrint + lLineEndChar;
        System.out.println( lStringToPrint );
        return lStringToPrint;
    }

    /**
     * Print the text as Single column
     * @param PrintText1 Key text
     * @param PrintText2 value text
     * @return The printed String
     */
    protected String printColumn( String PrintText1, String PrintText2 )
    {
        int lScrLength = (lScreenLength) / 2;
        String lStringToPrint = "" + lLineStartChar;
        for ( int i = 1; i < lRightPad; i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }
        lStringToPrint = lStringToPrint + PrintText1;
        for ( int i = lStringToPrint.length(); i < lScrLength; i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }
        if ( PrintText1.length() + PrintText2.length() == 0 )
        {
            lStringToPrint = lStringToPrint + "  ";
        }
        else
        {
            lStringToPrint = lStringToPrint + ": ";
        }
        lStringToPrint = lStringToPrint + PrintText2;
        lScrLength = lScrLength + lScrLength;
        for ( int i = lStringToPrint.length(); i < lScrLength - 1; i++ )
        {
            lStringToPrint = lStringToPrint + " ";
        }
        lStringToPrint = lStringToPrint + lLineEndChar;
        System.out.println( lStringToPrint );
        return lStringToPrint;
    }

    /**
     * Prints the header strip for the screen length
     * @return
     */
    protected String printHeader()
    {
        String lStringToPrint = "" + lHeaderStartChar;
        for ( int i = 0; i < lScreenLength - 2; i++ )
        {
            lStringToPrint = lStringToPrint + lHeaderMidChar;
        }
        lStringToPrint = lStringToPrint + lHeaderEndChar;
        System.out.println( lStringToPrint );
        return lStringToPrint;
    }

    /**
     * To get the screen length
     * @return
     */
    protected int getScreenLength()
    {
        return lScreenLength;
    }

    /**
     * To set the screen length
     * @param lScreenLength
     */
    protected void setScreenLength( int lScreenLength )
    {
        this.lScreenLength = lScreenLength;
    }
}
